import GameData from "./GameData";
import vv from "./vv";
import v from "./v";

// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    onCollisionEnter(other, self)
    {
        let luogang = 
        {
            "luogang":"哈哈",
            "luogang1":"哈哈",
            "luogang2":"哈哈",
            "luogang3":"哈哈",
            "luogang4":"哈哈",
            "luogang5":"哈哈"
        }
        if(other.node.name == '晒车回正')
        {
            console.log('开始加速')
            let action = cc.moveTo(0.5,new cc.Vec2(-3402,3972)).easing(cc.easeSineIn())
            if(this.node!=null)
            {
                this.node.runAction(action)
                this.node.getComponent(cc.RigidBody).linearVelocity  = new cc.Vec2(0,GameData.Instance.speed*2)
            }
        }

        if(other.node.name == '沙道减速')
        {
            let luogang = 
            {
                "luogang":"哈哈",
                "luogang1":"哈哈",
                "luogang2":"哈哈",
                "luogang3":"哈哈",
                "luogang4":"哈哈",
                "luogang5":"哈哈"
            }
        }

        if(other.node.name == '高架')
        {
            let luogang = 
            {
                "luogang":"哈哈",
                "luogang1":"哈哈",
                "luogang2":"哈哈",
                "luogang3":"哈哈",
                "luogang4":"哈哈",
                "luogang5":"哈哈"
            }
            v.emit('gaojia')
        }

        if(other.node.name == '晒车减速')
        {
            let luogang = 
            {
                "luogang":"哈哈",
                "luogang1":"哈哈",
                "luogang2":"哈哈",
                "luogang3":"哈哈",
                "luogang4":"哈哈",
                "luogang5":"哈哈"
            }
            console.log('开始减速')
            if(GameData.Instance.Onshaichecar == '葱花面包'&&GameData.Instance.speed<1000)
            {
                GameData.Instance.speed +=40
            }
            if(GameData.Instance.Onshaichecar == '橘色雄鹿'&&GameData.Instance.speed<1100)
            {
                let luogang = 
                {
                    "luogang":"哈哈",
                    "luogang1":"哈哈",
                    "luogang2":"哈哈",
                    "luogang3":"哈哈",
                    "luogang4":"哈哈",
                    "luogang5":"哈哈"
                }
                GameData.Instance.speed +=40
            }
            if(GameData.Instance.Onshaichecar == '叉车'&&GameData.Instance.speed<1150)
            {
                GameData.Instance.speed +=40
            }
            if(GameData.Instance.Onshaichecar == '小橘牛'||GameData.Instance.Onshaichecar == '顺丰小黑'||GameData.Instance.Onshaichecar == '白色幽灵'||GameData.Instance.Onshaichecar == '韵达电动车')
            {
                let luogang = 
                {
                    "luogang":"哈哈",
                    "luogang1":"哈哈",
                    "luogang2":"哈哈",
                    "luogang3":"哈哈",
                    "luogang4":"哈哈",
                    "luogang5":"哈哈"
                }
                if(GameData.Instance.speed<1200)
                {
                    GameData.Instance.speed +=40
                }
            }

            if(GameData.Instance.Onshaichecar == '大脚怪'&&GameData.Instance.speed<1250)
            {
                GameData.Instance.speed +=40
            }

            if(GameData.Instance.Onshaichecar == '救火车'||GameData.Instance.Onshaichecar == '黄卡'||GameData.Instance.Onshaichecar == '铲车'||GameData.Instance.Onshaichecar == '韵达电动车')
            {
                let luogang = 
                {
                    "luogang":"哈哈",
                    "luogang1":"哈哈",
                    "luogang2":"哈哈",
                    "luogang3":"哈哈",
                    "luogang4":"哈哈",
                    "luogang5":"哈哈"
                }
                if(GameData.Instance.speed<1300)
                {
                    GameData.Instance.speed +=40
                }
            }

            if(GameData.Instance.Onshaichecar == '黑影23号'||GameData.Instance.Onshaichecar == '绿影')
            {
                let luogang = 
                {
                    "luogang":"哈哈",
                    "luogang1":"哈哈",
                    "luogang2":"哈哈",
                    "luogang3":"哈哈",
                    "luogang4":"哈哈",
                    "luogang5":"哈哈"
                }
                if(GameData.Instance.speed<1400)
                {
                    GameData.Instance.speed +=40
                }
            }
          
            this.node.getComponent(cc.RigidBody).linearVelocity  = new cc.Vec2(0,GameData.Instance.speed)
        }
    }
    start () {

    }

    // update (dt) {}
}
